package com.zkzx.company.api.service.driver;

import com.zkzx.common.driver.model.DriverVO;
import com.zkzx.common.truck.model.TruckVO;
import com.zkzx.company.api.client.driver.DriverClient;
import com.zkzx.company.api.client.truck.TruckClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;

/**
 * 北京中科智兴物联科技有限公司 @版权所有
 *
 * @Author: zhaoyihe@zkraising.com
 * @Date: 2021/05/17/10:57
 * @Description:
 */

@Slf4j
@Service
public class DriverService {

    @Autowired
    private TruckClient truckClient;

    @Autowired
    private DriverClient driverClient;

    /**
     * 根据id获取司机信息
     * @param id 司机id
     * @param companyId 公司id
     * @return 司机详情信息
     */

    public DriverVO getById(Integer id, Integer companyId,Integer userId){

        DriverVO driverVO = driverClient.getById(id, companyId);

        if (Objects.isNull(driverVO)){
            return null;
        }
        if (null !=driverVO.getTruckId()){
            TruckVO truckVO = truckClient.getById(driverVO.getTruckId(), companyId, userId);
            if (Objects.nonNull(truckVO)){
                driverVO.setTruck(truckVO.getHeaderLicenseVO().getLicence());
            }
        }

        return driverVO;
    }


}


